from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-09-08 14:02:44.998512
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 08, Sep, 2022
Time: 14:02:50
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.3612
Nobs: 773.000 HQIC: -50.6943
Log likelihood: 9892.30 FPE: 7.82148e-23
AIC: -50.9026 Det(Omega_mle): 6.96705e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298668 0.054359 5.494 0.000
L1.Burgenland 0.106984 0.036197 2.956 0.003
L1.Kärnten -0.106787 0.019237 -5.551 0.000
L1.Niederösterreich 0.205350 0.075755 2.711 0.007
L1.Oberösterreich 0.114810 0.073309 1.566 0.117
L1.Salzburg 0.253369 0.038742 6.540 0.000
L1.Steiermark 0.035947 0.050504 0.712 0.477
L1.Tirol 0.106825 0.040923 2.610 0.009
L1.Vorarlberg -0.060652 0.035194 -1.723 0.085
L1.Wien 0.050135 0.065148 0.770 0.442
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059029 0.112864 0.523 0.601
L1.Burgenland -0.033972 0.075154 -0.452 0.651
L1.Kärnten 0.047426 0.039941 1.187 0.235
L1.Niederösterreich -0.176595 0.157288 -1.123 0.262
L1.Oberösterreich 0.395771 0.152208 2.600 0.009
L1.Salzburg 0.289971 0.080439 3.605 0.000
L1.Steiermark 0.105676 0.104860 1.008 0.314
L1.Tirol 0.314309 0.084967 3.699 0.000
L1.Vorarlberg 0.027266 0.073073 0.373 0.709
L1.Wien -0.021753 0.135265 -0.161 0.872
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191697 0.027917 6.867 0.000
L1.Burgenland 0.089440 0.018590 4.811 0.000
L1.Kärnten -0.008520 0.009879 -0.862 0.388
L1.Niederösterreich 0.260709 0.038905 6.701 0.000
L1.Oberösterreich 0.133900 0.037649 3.557 0.000
L1.Salzburg 0.046088 0.019897 2.316 0.021
L1.Steiermark 0.018187 0.025937 0.701 0.483
L1.Tirol 0.093124 0.021017 4.431 0.000
L1.Vorarlberg 0.058360 0.018075 3.229 0.001
L1.Wien 0.118117 0.033458 3.530 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.108182 0.028398 3.810 0.000
L1.Burgenland 0.047434 0.018910 2.508 0.012
L1.Kärnten -0.014879 0.010049 -1.481 0.139
L1.Niederösterreich 0.191674 0.039575 4.843 0.000
L1.Oberösterreich 0.289973 0.038297 7.572 0.000
L1.Salzburg 0.111616 0.020239 5.515 0.000
L1.Steiermark 0.102950 0.026384 3.902 0.000
L1.Tirol 0.110583 0.021379 5.173 0.000
L1.Vorarlberg 0.069698 0.018386 3.791 0.000
L1.Wien -0.017968 0.034034 -0.528 0.598
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.131308 0.051575 2.546 0.011
L1.Burgenland -0.051192 0.034343 -1.491 0.136
L1.Kärnten -0.040299 0.018252 -2.208 0.027
L1.Niederösterreich 0.170394 0.071876 2.371 0.018
L1.Oberösterreich 0.138565 0.069554 1.992 0.046
L1.Salzburg 0.287718 0.036758 7.827 0.000
L1.Steiermark 0.034097 0.047918 0.712 0.477
L1.Tirol 0.161918 0.038827 4.170 0.000
L1.Vorarlberg 0.100707 0.033392 3.016 0.003
L1.Wien 0.068703 0.061812 1.111 0.266
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056273 0.041057 1.371 0.170
L1.Burgenland 0.040430 0.027339 1.479 0.139
L1.Kärnten 0.050709 0.014529 3.490 0.000
L1.Niederösterreich 0.220965 0.057217 3.862 0.000
L1.Oberösterreich 0.283151 0.055369 5.114 0.000
L1.Salzburg 0.045503 0.029262 1.555 0.120
L1.Steiermark -0.000971 0.038145 -0.025 0.980
L1.Tirol 0.147451 0.030909 4.770 0.000
L1.Vorarlberg 0.073058 0.026582 2.748 0.006
L1.Wien 0.084202 0.049206 1.711 0.087
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.180495 0.049156 3.672 0.000
L1.Burgenland -0.006418 0.032732 -0.196 0.845
L1.Kärnten -0.061268 0.017396 -3.522 0.000
L1.Niederösterreich -0.083720 0.068505 -1.222 0.222
L1.Oberösterreich 0.195785 0.066292 2.953 0.003
L1.Salzburg 0.056737 0.035034 1.619 0.105
L1.Steiermark 0.231336 0.045670 5.065 0.000
L1.Tirol 0.493747 0.037006 13.342 0.000
L1.Vorarlberg 0.048076 0.031826 1.511 0.131
L1.Wien -0.052589 0.058913 -0.893 0.372
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166229 0.056419 2.946 0.003
L1.Burgenland -0.010248 0.037569 -0.273 0.785
L1.Kärnten 0.067142 0.019966 3.363 0.001
L1.Niederösterreich 0.206327 0.078626 2.624 0.009
L1.Oberösterreich -0.071053 0.076086 -0.934 0.350
L1.Salzburg 0.211510 0.040210 5.260 0.000
L1.Steiermark 0.115720 0.052418 2.208 0.027
L1.Tirol 0.071898 0.042474 1.693 0.091
L1.Vorarlberg 0.121622 0.036528 3.330 0.001
L1.Wien 0.122433 0.067617 1.811 0.070
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.357711 0.032634 10.961 0.000
L1.Burgenland 0.005325 0.021731 0.245 0.806
L1.Kärnten -0.023318 0.011549 -2.019 0.043
L1.Niederösterreich 0.214845 0.045479 4.724 0.000
L1.Oberösterreich 0.188010 0.044010 4.272 0.000
L1.Salzburg 0.046264 0.023258 1.989 0.047
L1.Steiermark -0.015586 0.030320 -0.514 0.607
L1.Tirol 0.106488 0.024568 4.334 0.000
L1.Vorarlberg 0.073550 0.021129 3.481 0.000
L1.Wien 0.048085 0.039111 1.229 0.219
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.040185 0.148441 0.192582 0.156746 0.124640 0.113023 0.065971 0.222386
Kärnten 0.040185 1.000000 -0.004022 0.132555 0.041501 0.095761 0.430486 -0.052271 0.100284
Niederösterreich 0.148441 -0.004022 1.000000 0.337867 0.151661 0.298383 0.108155 0.183442 0.323717
Oberösterreich 0.192582 0.132555 0.337867 1.000000 0.228738 0.330284 0.172897 0.167903 0.265160
Salzburg 0.156746 0.041501 0.151661 0.228738 1.000000 0.147531 0.122649 0.147395 0.133587
Steiermark 0.124640 0.095761 0.298383 0.330284 0.147531 1.000000 0.151805 0.138605 0.079573
Tirol 0.113023 0.430486 0.108155 0.172897 0.122649 0.151805 1.000000 0.115110 0.153547
Vorarlberg 0.065971 -0.052271 0.183442 0.167903 0.147395 0.138605 0.115110 1.000000 0.006760
Wien 0.222386 0.100284 0.323717 0.265160 0.133587 0.079573 0.153547 0.006760 1.000000